#!/bin/sh

inputfile=$1
outputfile=outputfile
tmpfile=.tmpfile
arrayfile=("bzImage" "firewall.gz" "triones.tgz" "System.map" "version" "grub.conf")

dd if=$inputfile of=$tmpfile bs=64 count=1

i=0
offset=0
while read line; do
	case $i in
	0)
		type=$line
		;;
	1)
		num=$line
		;;
	$[$num+2])
		exit 0
		;;
	*)
		array[$i-2]=$line
		;;
	esac

	len=`expr length $line`
	offset=$[$offset+len+1]
	i=$[$i+1]

done < $tmpfile

rm $tmpfile

echo "offset $offset"

i=0
while [ $i -lt $num ]; do
	len=${array[$i]};
	
	echo $len

	dd if=$inputfile of=$outputfile ibs=1 obs=512 count=$len skip=$offset
	mv $outputfile ${arrayfile[$i]} 

	offset=$[$offset+$len]
	i=$[$i+1]
done


